package com.usian.admin.controller;

import com.usian.admin.service.LoginService;
import com.usian.api.admin.LoginControllerApi;
import com.usian.common.sample.Sample;
import com.usian.model.admin.dtos.AdUserDto;
import com.usian.model.admin.pojos.AdUser;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.user.pojos.ApUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/login")
public class LoginController implements LoginControllerApi {
    @Autowired
    LoginService loginService;
@RequestMapping("adduser")
    @Override
    public ResponseResult addUser(@RequestBody AdUser adUser) throws  Exception{
    boolean nickname = Sample.Nickname(adUser.getNickname());
    if (nickname){
         loginService.addUser(adUser);
         return new ResponseResult<>().ok(null);
    }else {
        return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
    }

    }
@PostMapping("in")
    @Override
    public ResponseResult login(@RequestBody AdUserDto adUserDto) {
        return loginService.login(adUserDto);
    }
}
